package com.central.apps.handler;

import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class BarcodeHandler extends LvBaseHandler {
    @Autowired
    private HandlerService handlerService;
    public void beforDelete(String app, String objName, Long id, boolean isLogic) {
        //条码管理，删除前，将采购接收或者入库申请中的状态改为0
        try {
            String sql = "select * from gq_barcode where id = "+id;
            List<Map<String, Object>> list = handlerService.findBySql(sql);
            if (CollectionUtils.isNotEmpty(list)) {
                String addid = (String) list.get(0).get("addid");
                String addtype = (String) list.get(0).get("addtype");
                String upd = "update "+addtype +" set converttobc =0 where id = "+addid;
                handlerService.updateBySql(upd);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
